var a = getApp(), t = "plugin.supplier.frontend.shop.index.search-goods";

Page({
    data: {
        language: "",
        customer_open: !0,
        show1: !1,
        service_QRcode: "",
        service_mobile: "",
        cservice: "",
        id: "",
        order_id: "",
        tab: 0,
        sliderShow: !1,
        indexData: {},
        supplierInfo: {},
        goodsArr: [],
        good_loading: !1,
        good_allLoaded: !1,
        good_goload: !0,
        good_isLoadMore: !0,
        good_page: 1,
        good_total_page: 0,
        order_field: "",
        order_by: "",
        actGoodsArr: [],
        act_loading: !1,
        act_allLoaded: !1,
        act_goload: !0,
        act_isLoadMore: !0,
        act_page: 1,
        act_total_page: 0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        roomdataBol: !1,
        roomdata: [],
        keyword: null,
        categoryInfo: {},
        Height: 0,
        LastHeight: 0
    },
    onLoad: function(a) {
        this.init(), a.id && this.setData({
            id: a.id
        }), wx.setNavigationBarTitle({
            title: "供应商店铺"
        }), 1 == a.fromOrder && this.setData({
            id: "",
            order_id: a.id
        }), this.getIndexData();
    },
    loadimg: function(a) {
        var t = wx.getSystemInfoSync().windowWidth * a.detail.height / a.detail.width;
        parseInt(t) > this.data.LastHeight && (this.setData({
            Height: t
        }), this.data.LastHeight = parseInt(t));
    },
    onChange: function(a) {
        this.data.roomBol = !1, this.setData({
            tab: a.currentTarget.dataset.key
        }), "商品" == a.currentTarget.dataset.title ? (this.setData({
            good_page: 1
        }), this.getGoodsData()) : "活动" == a.currentTarget.dataset.title ? this.getActivityData() : "直播列表" == a.currentTarget.dataset.title && (this.data.roomBol = !0, 
        this.getLiveList());
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    getActivityData: function() {
        var t = this, e = a.getNetAddresss("plugin.supplier.frontend.shop.index.goods-limit");
        a._getNetWork({
            url: e,
            data: {
                sid: this.data.id
            },
            success: function(a) {
                var e = a.data;
                1 == e.result && (console.log(e.data.list.data), t.setData({
                    actGoodsArr: e.data.list.data,
                    act_total_page: e.data.list.last_page
                }));
            }
        });
    },
    getActivityMoreData: function() {
        var t = this;
        if (this.data.act_isLoadMore = !1, !(this.data.act_page >= this.data.act_total_page)) {
            this.data.act_page = this.data.act_page + 1;
            var e = a.getNetAddresss("plugin.supplier.frontend.shop.index.goods-limit");
            a._getNetWork({
                url: e,
                data: {
                    sid: this.data.id,
                    page: this.data.act_page
                },
                success: function(a) {
                    var e = a.data;
                    if (t.data.act_isLoadMore = !0, 1 == e.result) {
                        var o = t.data.actGoodsArr.concat(e.data.list.data);
                        t.setData({
                            actGoodsArr: o
                        });
                    } else t.data.act_page = t.data.act_page - 1, t.data.act_isLoadMore = !1;
                }
            });
        }
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (this.data.current_page >= this.data.good_total_page) wx.showToast({
            title: "暂无更多",
            icon: "none",
            duration: 1e3
        }); else if (1 == this.data.tab) {
            var a = this.data.good_page + 1;
            this.setData({
                good_page: a
            }), this.nexTgetGoodsData();
        } else 2 == this.data.tab && this.getActivityMoreData();
        this.data.roomBol && this.data.roomdataBol && (this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据"));
    },
    _getMoreData: function() {
        var t = this, e = a.getNetAddresss("plugin.supplier.frontend.shop.index.get-room");
        t.data.isLoadMore = !1, this.data.page >= this.data.total_page || (this.data.page = this.data.page + 1, 
        a._postNetWork({
            url: e,
            showToastIn: !1,
            data: {
                page: this.data.page,
                supplier_id: this.data.id
            },
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    isLoadMore: !0,
                    roomdata: t.data.roomdata.concat(e.data.data)
                }) : t.setData({
                    page: t.data.page - 1,
                    isLoadMore: !1
                });
            },
            fail: function(a) {
                console.log(a.msg);
            }
        }));
    },
    onShareAppMessage: function() {
        return {
            path: "/packageA/member/supplier/SupplierShop/SupplierShop?id=" + this.data.id
        };
    },
    init: function() {
        this.setData({
            customer_open: !0,
            show1: !1,
            service_QRcode: "",
            service_mobile: "",
            cservice: ""
        });
    },
    callPhone: function() {
        wx.makePhoneCall({
            phoneNumber: this.data.service_mobile
        });
    },
    showPop: function() {
        this.data.customer_open && this.setData({
            show1: !0
        });
    },
    closePop: function() {
        this.setData({
            show1: !1
        });
    },
    gopage: function(a) {
        var t = a.currentTarget.dataset.status, e = a.currentTarget.dataset.id, o = a.currentTarget.dataset.backid;
        1 == t ? wx.navigateTo({
            url: "/packageD/directSeeding/livePage/livePage?id=" + e + "&playerType=live"
        }) : 2 == t ? wx.navigateTo({
            url: "/packageD/directSeeding/livePage/livePage?id=" + e + "&playerType=video&backid=" + o
        }) : 3 == t && wx.navigateTo({
            url: "/packageD/directSeeding/foreshow/foreshow?id=" + e
        });
    },
    goToSuppliereInfo: function() {
        wx.navigateTo({
            url: "/packageA/member/supplier/SupplierInfo/SupplierInfo?id=" + this.data.id
        });
    },
    gotoChat: function(t) {
        var e = t.currentTarget.dataset.cservice;
        wx.navigateTo({
            url: e,
            fail: function(t) {
                a.tips("客服路由出错");
            }
        });
    },
    getIndexData: function() {
        var t = this, e = a.getNetAddresss("plugin.supplier.frontend.shop.index.index");
        e += "&sid=" + this.data.id, e += "&order_id=" + this.data.order_id, a._getNetWork({
            url: e,
            success: function(e) {
                var o = e.data;
                if (1 == o.result) {
                    o.data.is_room && 1 == o.data.is_room && t.setData({
                        roomdataBol: !0
                    }), t.setData({
                        id: o.data.supplier.supplier_id
                    });
                    for (var i = 0; i < o.data.list_is_recommand.length; i++) parseInt(Number(0 == o.data.list_is_recommand[i].market_price)) ? o.data.list_is_recommand[i].notMarket_price = 0 : o.data.list_is_recommand[i].notMarket_price = 1;
                    for (var s = 0; s < o.data.advs.length; s++) a._isTextEmpty(o.data.advs[s].img) ? o.data.advs[s].imagShow = !1 : o.data.advs[s].imagShow = !0;
                    t.setData({
                        indexData: o.data,
                        supplierInfo: o.data.supplier,
                        customer_open: "1" == o.data.customer_open,
                        service_QRcode: o.data.service_QRcode,
                        service_mobile: o.data.service_mobile,
                        cservice: o.data.cservice
                    });
                }
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    getLiveList: function() {
        var t = this, e = a.getNetAddresss("plugin.supplier.frontend.shop.index.get-room");
        a._postNetWork({
            url: e,
            showToastIn: !1,
            data: {
                page: this.data.page,
                supplier_id: this.data.id
            },
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    total_page: e.data.last_page,
                    roomdata: e.data.data
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    getGoodsData: function() {
        var e = this, o = a.getNetAddresss(t);
        o += "&sid=" + this.data.id, o += "&page=" + this.data.good_page, o += "&order_field=" + this.data.order_field, 
        o += "&order_by=" + this.data.order_by, o += "&search[keyword]=".concat(this.data.keyword || ""), 
        a._getNetWork({
            url: o,
            success: function(a) {
                var t = a.data;
                1 == t.result && e.setData({
                    goodsArr: t.data.data,
                    good_total_page: t.data.last_page,
                    current_page: t.data.current_page
                });
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    nexTgetGoodsData: function() {
        var e = this, o = a.getNetAddresss(t);
        o += "&sid=" + this.data.id, o += "&page=" + this.data.good_page, o += "&order_field=" + this.data.order_field, 
        o += "&order_by=" + this.data.order_by, o += "&search[keyword]=", a._getNetWork({
            url: o,
            success: function(a) {
                var t = a.data;
                1 == t.result && e.setData({
                    goodsArr: e.data.goodsArr.concat(t.data.data),
                    good_total_page: t.data.last_page,
                    current_page: t.data.current_page
                });
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    toggle: function(a) {
        var t = "";
        switch (a.currentTarget.dataset.idx) {
          case 2:
            this.setData({
                hascolor: 2
            }), "2_2" == this.data.colorshow ? (this.setData({
                colorshow: "2_1"
            }), t = "show_sales", this.setData({
                order_field: t,
                order_by: "asc"
            })) : (this.setData({
                colorshow: "2_2"
            }), t = "show_sales", this.setData({
                order_field: t,
                order_by: "desc"
            }));
            break;

          case 3:
            this.setData({
                hascolor: 3
            }), "3_2" == this.data.colorshow ? (this.setData({
                colorshow: "3_1"
            }), t = "price", this.setData({
                order_field: t,
                order_by: "asc"
            })) : (this.setData({
                colorshow: "3_2"
            }), t = "price", this.setData({
                order_field: t,
                order_by: "desc"
            }));
            break;

          case 5:
            this.setData({
                hascolor: 5
            }), "5_2" == this.data.colorshow ? (this.setData({
                colorshow: "5_1"
            }), t = "id", this.setData({
                order_field: t,
                order_by: "asc"
            })) : (this.setData({
                colorshow: "5_2"
            }), t = "id", this.setData({
                order_field: t,
                order_by: "desc"
            }));
        }
        this.getGoodsData();
    },
    goToSearch: function() {
        wx.navigateTo({
            url: "/packageA/member/supplier/SupplierSearch/SupplierSearch?id=" + this.data.id
        });
    },
    toggleSlide: function() {
        this.setData({
            sliderShow: !this.data.sliderShow
        });
    },
    goToUrl: function(a) {
        var t = a.currentTarget.dataset.type, e = a.currentTarget.dataset.url;
        "route" == t && "home" == e ? wx.reLaunch({
            url: "/packageG/index/index"
        }) : "route" == t && "orderlist" == e ? wx.navigateTo({
            url: "/packageA/member/myOrder_v2/myOrder_v2"
        }) : "route" == t && "member" == e ? wx.reLaunch({
            url: "/packageG/member_v2/member_v2"
        }) : "href" == t && console.log(e);
    },
    goToDetail: function(a) {
        var t = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + t
        });
    },
    goToMoreHot: function() {
        wx.navigateTo({
            url: "/packageA/member/supplier/SupplierSearch/SupplierSearch?id=" + this.data.id + "&hot=1"
        });
    },
    searchConfirm: function() {
        var a = this;
        this.setData({
            good_page: 1,
            tab: 1,
            goodsArr: []
        }, function() {
            a.getGoodsData();
        });
    }
});